package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"smart-sensor-cloud/pkg/util"
)

func FaultHandler(c *gin.Context) {
	c.Next()

	if !c.Writer.Written() {
		errT := c.MustGet("error")
		switch err := errT.(type) {
		case *util.Error:
			c.JSON(http.StatusOK, err)
		default:
			panic(err.(error).Error())
		}
	}
}
